package com.guigu.qingcheng.servicebusiness.controller;


import com.guigu.qingcheng.pojo.bussiness.TbActivity;
import com.guigu.qingcheng.servicebusiness.service.TbActivityService;
import com.guigu.qingcheng.utils.R;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@RestController
@RequestMapping("/servicebusiness/tb-activity")
public class TbActivityController {

    @Resource
    private TbActivityService tbActivityService;

    @GetMapping("/findAll")
    public R findAll(){
        List<TbActivity> list = tbActivityService.list(null);
            if (list.size()>0)
            return R.ok().data("list",list);
            return R.error();
    }

    @PostMapping("/findPage")
    public R findPage(@RequestBody Map<String,Object> searchMap, @RequestParam("page") Integer page, @RequestParam("size") Integer size){
        R page1 = tbActivityService.findPage(searchMap, page, size);
        return R.ok().data("page1",page1);
    }

    @GetMapping("/findById")
    public R findById(@RequestParam("id") Integer id){
        TbActivity byId = tbActivityService.findById(id);
        return R.ok().data("byId",byId);
    }

    @PostMapping("/insert")
    public R insert(@RequestBody TbActivity tbActivity){
        boolean save = tbActivityService.save(tbActivity);
        if (save)
        return R.ok();
        return R.error();
    }

    @PostMapping("/update")
    public R update(@RequestBody TbActivity tbActivity){
        boolean b = tbActivityService.updateById(tbActivity);
        if (b) {
            return R.ok();
        }else {
            return R.error();
        }
    }

    @GetMapping("/delete")
    public R delete(@Param("id") Integer id){
        boolean b = tbActivityService.removeById(id);
        if (b)
        return R.ok();
        return R.error();
    }
}

